package com.olap.starter.util.tree;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author WBG
 * @date 2021/11/9 22:04
 * @describe
 */
public class TreeNode implements Serializable {
    private static final long serialVersionUID = 1L;
    String key;
    String value;
    String parentKey;
    String index;
    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    List<TreeNode> children = null;

    public TreeNode() {
    }

    public TreeNode(String key, String value, String parentKey) {
        this.key = key;
        this.value = value;
        this.parentKey = parentKey;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }
    public void addChildren(TreeNode nodeDto) {
        if(children == null){
            children = new ArrayList<>();
        }
        children.add(nodeDto);
    }
    public void setValue(String value) {
        this.value = value;
    }

    public String getParentKey() {
        return parentKey;
    }

    public void setParentKey(String parentKey) {
        this.parentKey = parentKey;
    }

    public String getIndex() {
        return index;
    }

    public void setIndex(String index) {
        this.index = index;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "key='" + key + '\'' +
                ", value='" + value + '\'' +
                ", parentKey='" + parentKey + '\'' +
                ", index='" + index + '\'' +
                ", children=" + children +
                '}';
    }
}
